package com.liuli.action;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.liuli.entity.ResumeEdu;
import com.liuli.entity.ResumePractice;
import com.liuli.service.ResumePracticeService;
import com.liuli.utils.ReturnJson;
import com.opensymphony.xwork2.ModelDriven;

public class ResumePracticeAction extends BaseAction implements ModelDriven<ResumePractice>{
	

	@Autowired
	@Qualifier("practiceService")
	private ResumePracticeService practiceService;
	
	private ResumePractice practice;
	

	/**
	 * 添加工作经历
	 */
	public void  addPractice(){
		JSONObject json = new JSONObject();
		try {
			practiceService.save(practice);
			json.put("errcode", 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}
	
	/**
	 * 修改工作经历
	 */
	public void  editPractice(){
		JSONObject json = new JSONObject();
		try {
			practiceService.update(practice);
			json.put("errcode", 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}
	
	/**
	 * 删除工作经历
	 */
	public void  delPractice(){
		JSONObject json = new JSONObject();
		try {
			practiceService.delete(practice.getPrid());
			json.put("errcode", 0);
		} catch (Exception e) {
			json.put("errcode", 40014);  //删除失败
			e.printStackTrace();
		}
	  ReturnJson.reponse(json.toString());
	}

	
	

	public ResumePracticeService getPracticeService() {
		return practiceService;
	}

	public void setPracticeService(ResumePracticeService practiceService) {
		this.practiceService = practiceService;
	}

	public ResumePractice getPractice() {
		return practice;
	}

	public void setPractice(ResumePractice practice) {
		this.practice = practice;
	}
	
	@Override
	public ResumePractice getModel() {
		// TODO Auto-generated method stub
		if(practice == null){
			practice = new ResumePractice();
		}
		return practice;
	}
	
	
	

}
